class Solution:
    def search(self, nums, target):
        left=0
        right=len(nums)-1
        while left<=right:
            mid=(left+right)//2
            # print(left,mid,right)
            if target==nums[mid]:
                return mid
            # 左半边顺序
            if nums[mid]>=nums[left]:
                if target>=nums[left] and target<=nums[mid]:
                    right=mid-1
                else:
                    left=mid+1
            # 右半边顺序
            else:
                if target>=nums[mid] and target<=nums[right]:
                    left=mid+1
                else:
                    right=mid-1
        return -1

def main():
    sol=Solution()
    nums = [3,1]
    target = 3
    res=sol.search(nums,target)
    print(res)

main()